import { createHashRouter, Navigate } from "react-router-dom";

import Control from "@/views/Control";
import DashBoard from "@/views/DashBoard";
import Vports from "@/views/Vports";
import Operation from "@/views/Operation";

import System from "@/views/System";
import Camera from "@/views/System/Camera";
import Keypad from "@/views/System/Keypad";
import Protocol from "@/views/System/Protocol";
import Fault from "@/views/System/Fault";


const routes = [
  {
    path: "",
    name: "",
    element: <Navigate to="/dashBoard" />, // 默认重定向到登录页面
  },
  {
    path: "control",
    name: "车辆控制",
    element: <Control />,
  },
  {
    path: "dashBoard",
    name: "仪表盘",
    element: <DashBoard />,
  },
  {
    path: "vports",
    name: "多视口",
    element: <Vports />,
  },
  {
    path: "operation",
    name: "运行状态",
    element: <Operation />,
  },
  {
    path: "system",
    name: "系统设置",
    element: <System />,
    children: [
      {
        path: "camera",
        name: "摄像头设置",
        element: <Camera />,
      },
      {
        path: "keypad",
        name: "按键设置",
        element: <Keypad />,
      },
      {
        path: "protocol",
        name: "协议设置",
        element: <Protocol />,
      },
      {
        path: "fault",
        name: "故障日志",
        element: <Fault />,
      },
    ],
  },
];

export function getChildrenRoutes(path: string) {
  if (!path) {
    return routes;
  }
  const route = routes.find((route) => route.path === path);
  return route?.children || [];
}

export default createHashRouter(routes);
